<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <div id="app1"></div>
    <div id="app2"></div>
    <script src="../js/babel.min.js"></script>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/prop-types.js"></script>
    <script type="text/babel">
      class Demo extends React.Component {
        state = { isTrue: true };
        showData = () => {
          alert(this.input1.value);
        };
        change = () => {
          this.setState({ isTrue: !this.state.isTrue });
        };
        saveNode = (currentNode) => {
          console.log("update", currentNode);
          this.input1 = currentNode;
        };

        render() {
          const { isTrue } = this.state;
          return (
            <div>
              <h2> isTrue = {isTrue ? "真" : "假"} </h2>,
              {/*内联回调在进行页面更新的时候会调用两次 
			   进行页面更新会再次调用render进行渲染，回调函数会再次呗调用*/}
              {/*
              <input
                ref={(currentNode)=>{console.log("update",currentNode);this.input1 = currentNode}}
                id="input1"
                type="text"
                placeholder="点击按钮提示"
              />
			  */}
              <input
                ref={this.saveNode}
                id="input1"
                type="text"
                placeholder="点击按钮提示"
              />
              <button onClick={this.showData}>提示</button>
              <button onClick={this.change}>切换</button>
            </div>
          );
        }
      }

      ReactDOM.render(<Demo />, document.getElementById("app"));
    </script>
  </body>
</html>
